package com.example.tasksmcpserver.controller;

import com.example.tasksmcpserver.entity.Task;
import com.example.tasksmcpserver.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tasks")
public class TaskController {
    private final TaskService taskService;

    @Autowired
    public TaskController(TaskService taskService) {
        this.taskService = taskService;
    }

    @PostMapping
    public ResponseEntity<Task> createTask(@RequestParam String name, @RequestParam String category) {
        Task task = taskService.createTask(name, category);
        return ResponseEntity.ok(task);
    }

    @GetMapping("/search/name")
    public ResponseEntity<List<Task>> findTasksByName(@RequestParam String name) {
        List<Task> tasks = taskService.findTasksByName(name);
        return ResponseEntity.ok(tasks);
    }

    @GetMapping("/search/category")
    public ResponseEntity<List<Task>> findTasksByCategory(@RequestParam String category) {
        List<Task> tasks = taskService.findTasksByCategory(category);
        return ResponseEntity.ok(tasks);
    }
} 